/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package CastleDefense.Managers;

import javax.swing.JOptionPane;

import CastleDefense.Enemy;
import CastleDefense.Game;
import CastleDefense.Managers.GameManager.Difficulty;
import CastleDefense.Monster;
import CastleDefense.MonsterList;
import CastleDefense.Wave;

/**
 *
 * @author Administrator
 */
public class WaveManager
{  
	public WaveManager()
	{
	}
	
    public void doNextWave()
    {
        MonsterList ML       = Game.getMonsterList();
        Wave currentWave     = Game.getWaveList().getWaveByID(GameManager.getInstance().getCurrentWave());
        String[][] waveOrder = currentWave.getWaveArray();
        
        String name          = "";
        String sprite        = "";
        Monster mob;
        
        if(GameManager.getInstance().getDifficulty() == Difficulty.EASY)
        {
            for (int row=0; row<waveOrder.length; row++)
            {
                 for (int col=0; col<waveOrder[row].length; col++)
                 {
                     if(!waveOrder[row][col].equals(""))
                     {
                        mob    = ML.getMonsterByName(waveOrder[row][col]);
                        name   = mob.getName();
                        sprite = mob.getSprite();
                        
                        if(Game.getMonsterList().getMonsterByName(name).getSize().equals("BOSS")) //168x168
                        {
                            Enemy currentEnemy = new Enemy(sprite, name, (42), (168)-200, 1);
                            Game.addEnemy(currentEnemy);
                        }
                        else if(Game.getMonsterList().getMonsterByName(name).getSize().equals("MINIBOSS")) //84x84
                        {
                            Enemy currentEnemy = new Enemy(sprite, name, (col*42)+42, (84)-126, col+1);
                            Game.addEnemy(currentEnemy);
                        }
                        else //42x42
                        {
                            Enemy currentEnemy = new Enemy(sprite, name, (col*42)+42, (row*-48)-44, col+1);
                            Game.addEnemy(currentEnemy);
                        }
                     }
                 }
             }
        }
        else if(GameManager.getInstance().getDifficulty() == Difficulty.NORMAL)
        {
            System.out.println("TODO");
            JOptionPane.showMessageDialog(null, "Only Easy difficulty available in demo.");
            System.exit(0);
            //TODO
            /*
            for (int x=0;x<4;x++)
            {
                for (int y=0;y<4;y++)
                {
                    Enemy currentEnemy = new Enemy(sprite, name,(x*42)+42, (y*-48)-44, x+1);
                    Game.addEnemy(currentEnemy);
                }

                for (int y=0;y<4;y++)
                {
                    Enemy currentEnemy = new Enemy(sprite, name,(x*42)+42, (y*-48)-328, x+1);
                    Game.addEnemy(currentEnemy);
                }
            }
            */
        }
        else if(GameManager.getInstance().getDifficulty() == Difficulty.HARD)
        {
            System.out.println("TODO");
            JOptionPane.showMessageDialog(null, "Only Easy difficulty available in demo.");
            System.exit(0);
            //TODO
            /*
            for (int x=0;x<4;x++)
            {
                for (int y=0;y<4;y++)
                {
                    Enemy currentEnemy = new Enemy(sprite, name,(x*42)+42, (y*-48)-44, x+1);
                    Game.addEnemy(currentEnemy);
                }

                for (int y=0;y<4;y++)
                {
                    Enemy currentEnemy = new Enemy(sprite, name,(x*42)+42, (y*-48)-328, x+1);
                    Game.addEnemy(currentEnemy);
                }

                for (int y=0;y<4;y++)
                {
                    Enemy currentEnemy = new Enemy(sprite, name,(x*42)+42, (y*-48)-618, x+1);
                    Game.addEnemy(currentEnemy);
                }
            }
            */
        }
    }
    
	public static final WaveManager getInstance()
	{
		return SingletonHolder.instance;
	}
	
	@SuppressWarnings("synthetic-access")
	public static class SingletonHolder
	{
		protected static final WaveManager instance = new WaveManager();
	}
}
